package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.SceneCommend;
import cn.wolfcode.trip.base.mapper.SceneCommendMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ISceneCommendService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SceneCommendServiceImpl implements ISceneCommendService {

    @Autowired
    private SceneCommendMapper sceneCommendMapper;

    public PageInfo<SceneCommend> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<SceneCommend> list = sceneCommendMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    public void saveOrUpdate(SceneCommend entity) {
        if (entity.getId() == null) {
            sceneCommendMapper.insert(entity);
        } else {
            sceneCommendMapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    public List<SceneCommend> listSceneCommend() {
        return sceneCommendMapper.selectAllCommends();
    }

    public List<SceneCommend> listCommend(Integer type) {
        return sceneCommendMapper.selectCommendByType(type);
    }
}
